﻿using MediatR;
using Warehouse.API.Applcation.Command.MovelibraryCommand;
using Warehouse.Infrstructre.Interface;

namespace Warehouse.API.Applcation.CommandHandlers.MovelibraryCommandHandlers
{
    /// <summary>
    /// 删除移库产品信息
    /// </summary>
    public class MovelibraryDelCommandHandlers:IRequestHandler<MovelibraryDelCommand,int>
    {
        private readonly IMovelibraryRepository _movelibraryRep;

        public MovelibraryDelCommandHandlers(IMovelibraryRepository movelibraryRep)
        {
            _movelibraryRep = movelibraryRep;
        }

        public async Task<int> Handle(MovelibraryDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await _movelibraryRep.GetAllAsyns()).Where(c => request.MovelibraryId.Contains(c.MovelibraryId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await _movelibraryRep.UpdateAsync(item);
            }
            return 1;
        }
    }
}
